package com.cenxi.controller;

import com.cenxi.common.dto.AccountDTO;
import com.cenxi.common.result.PageReq;
import com.cenxi.common.result.PageResp;
import com.cenxi.common.result.Req;
import com.cenxi.common.result.Resp;
import com.cenxi.common.vo.AccountVO;
import com.cenxi.manage.ManageAccountService;
import com.cenxi.utils.constants.Constants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @Author cenxi
 * @Date 2023/11/14 15:57
 * @Version 1.0
 */

@Api(tags = "账户接口")
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private ManageAccountService manageAccountService;

    @PostMapping("/page")
    @ApiOperation(value = "用户列表")
    public PageResp<AccountVO> page(@RequestBody PageReq<AccountDTO> req) {
        return manageAccountService.page(req);
    }

    @PostMapping("/create")
    @ApiOperation(value = "创建账户")
    public Resp<Boolean> create(@RequestBody Req<AccountDTO> req) {
        return manageAccountService.create(req);
    }

    @PostMapping("/finById")
    @ApiOperation(value = "根据id查询平台账户信息")
    public Resp<AccountVO> findById(@RequestBody Req<Long> req) {
        if (Objects.isNull(req.getData())) {
            return Resp.error("参数错误");
        }
        return manageAccountService.findById(req.getData());
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改账户")
    public Resp<Boolean> edit(@RequestBody Req<AccountDTO> req) {
        return manageAccountService.edit(req);
    }

    @PostMapping("/enable")
    @ApiOperation(value = "启用账户")
    public Resp<Boolean> enable(@RequestBody Req<List<Long>> req) {
        if (Objects.isNull(req.getData())) {
            return Resp.error("参数错误");
        }
        return manageAccountService.enable(req.getData(), Constants.ENABLE);
    }

    @PostMapping("/disable")
    @ApiOperation(value = "禁用账户")
    public Resp<Boolean> disable(@RequestBody Req<List<Long>> req) {
        if (Objects.isNull(req.getData())) {
            return Resp.error("参数错误");
        }
        return manageAccountService.disable(req.getData(), Constants.DISABLE);
    }

    @PostMapping("/deleteById")
    @ApiOperation(value = "根据id删除平台账户信息")
    public Resp<Boolean> deleteById(@RequestBody Req<List<Long>> req) {
        if (Objects.isNull(req.getData())) {
            return Resp.error("参数错误");
        }
        return manageAccountService.deleteById(req.getData());
    }

}
